package com.ruoyi.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.domain.CmsArticleInputFile;
import com.ruoyi.cms.service.ICmsArticleInputFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章导入Controller
 * 
 * @author fyliu
 * @date 2025-04-14
 */
@RestController
@RequestMapping("/cms/article_file")
public class CmsArticleInputFileController extends BaseController
{
    @Autowired
    private ICmsArticleInputFileService cmsArticleInputFileService;

    /**
     * 查询文章导入列表
     */
    @PreAuthorize("@ss.hasPermi('cms:article_file:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsArticleInputFile cmsArticleInputFile)
    {
        startPage();
        List<CmsArticleInputFile> list = cmsArticleInputFileService.selectCmsArticleInputFileList(cmsArticleInputFile);
        return getDataTable(list);
    }

    /**
     * 导出文章导入列表
     */
    @PreAuthorize("@ss.hasPermi('cms:article_file:export')")
    @Log(title = "文章导入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsArticleInputFile cmsArticleInputFile)
    {
        List<CmsArticleInputFile> list = cmsArticleInputFileService.selectCmsArticleInputFileList(cmsArticleInputFile);
        ExcelUtil<CmsArticleInputFile> util = new ExcelUtil<CmsArticleInputFile>(CmsArticleInputFile.class);
        util.exportExcel(response, list, "文章导入数据");
    }

    /**
     * 获取文章导入详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:article_file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmsArticleInputFileService.selectCmsArticleInputFileById(id));
    }

    /**
     * 新增文章导入
     */
    @PreAuthorize("@ss.hasPermi('cms:article_file:add')")
    @Log(title = "文章导入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsArticleInputFile cmsArticleInputFile)
    {
        return toAjax(cmsArticleInputFileService.insertCmsArticleInputFile(cmsArticleInputFile));
    }

    /**
     * 修改文章导入
     */
    @PreAuthorize("@ss.hasPermi('cms:article_file:edit')")
    @Log(title = "文章导入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsArticleInputFile cmsArticleInputFile)
    {
        return toAjax(cmsArticleInputFileService.updateCmsArticleInputFile(cmsArticleInputFile));
    }

    /**
     * 删除文章导入
     */
    @PreAuthorize("@ss.hasPermi('cms:article_file:remove')")
    @Log(title = "文章导入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsArticleInputFileService.deleteCmsArticleInputFileByIds(ids));
    }
}
